// pages/choose_series/details/index.js
import {
  wxRequest
} from '../../../utils/server.js';
const _wxRequest = new wxRequest();
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    options: {},
    modelImg: "",
    checkedId: '',
    colorList: [],
    uploadsUrl: app.globalData.uploadsUrl,
    hairColorNumList: [{
      note: "黑色",
      hairColorNum: 2,
      icon: "../../../image/black.png",
      checked: true
    },
    {
      hairColorNum: 1,
      note: "白色",
      icon: "../../../image/white.png",
      checked: false
    }
    ],
    x_list: [],
    itemColor: {}
  },

  //查询系列列表
  getlist: function () {
    var params = {
      pageSize: 100,
      pid: this.data.options.id,
    }
    _wxRequest.wxTonkenAjax({
      url: app.globalData.apiUrl + '/gds/protected/dyeColor/findListNew',
      method: 'POST',
      data: params
    }, (res) => {
      let list = res.list;
      this.setData({
        colorList: list
      }, () => {
        this.setDataX_list(2)
      });
    })
  },

  hairColorClick(e) {
    const haircolornum = e.currentTarget.dataset.haircolornum
    const hairColorNumList = this.data.hairColorNumList.map(e => { e.hairColorNum == haircolornum ? e.checked = true : e.checked = false; return e; })
    this.setData({
      hairColorNumList:hairColorNumList,
    })
    this.setDataX_list(haircolornum)
  },
  /**
   * 从data colorList中 筛选出横向列表
   * @param {int} haircolornum 1白色 2黑色
   */
  setDataX_list(haircolornum) {
    const colorList = this.data.colorList
    const x_list = colorList.map(e => e[haircolornum]).filter(e => e)
    const modelImg = x_list[0].modelImg
    this.setData({
      x_list,
      modelImg
    })
  },

  modelSelect(e) {
    const {
      item
    } = e.currentTarget.dataset
    this.setData({
      modelImg: item.modelImg,
      checkedId: item.id
    })
  },

  showblanking(e) {
    const {
      item
    } = e.currentTarget.dataset
    this.setData({
      itemColor: item
    })
    wx.navigateTo({
      url: '/pages/colors_project/index'
    })

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      options
    }, () => {
      this.getlist()
    })
  },


})